/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.vnf.bc;

import edu.upn.sigemfi.plt.bc.OrdenPagoFacadeLocal;
import edu.upn.sigemfi.plt.be.OrdenPago;
import java.awt.image.LookupOp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Administrador
 */
public class OrdenPagoDelegate {

    private OrdenPagoFacadeLocal local;

    public OrdenPagoDelegate(){
        local = lookupOrdenPagoFacade();
    }

    public OrdenPago buscarPorId(Long id) throws Exception {
        OrdenPago nroOrdenPago = null;
        try {
            nroOrdenPago = local.find(id);
        } catch (Exception ex) {
            local = lookupOrdenPagoFacade();
            throw new Exception("Buscar nro orden pago... " + ex.getMessage());
        }
        return nroOrdenPago;
    }

    private OrdenPagoFacadeLocal lookupOrdenPagoFacade() {
        try {
            Context c = new InitialContext();
            return (OrdenPagoFacadeLocal) c.lookup("java:comp/env/OrdenPagoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }


}
